package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/*
* 处理mybatis核心配置类
* */
public class MybatisConfig {

    //创建一个方法获取SqlSessionFactoryBean对象
    @Bean//将方法获取的对象存入IOC容器
    public SqlSessionFactoryBean getSqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource){//隐藏了一个@Autowired
        SqlSessionFactoryBean sb=new SqlSessionFactoryBean();
        sb.setDataSource(dataSource);
        sb.setTypeAliasesPackage("com.itheima.domain");
        return sb;
    }

    //创建一个方法获取MapperScannerConfigurer对象
    @Bean//将方法获取的对象存入IOC容器
    public MapperScannerConfigurer getMapperScannerConfigurer(){
        MapperScannerConfigurer mc=new MapperScannerConfigurer();
        mc.setBasePackage("com.itheima.mapper");
        return mc;
    }
}
